/*
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file wfqueuemanagerproxy.h
 * @author Davide Giuseppe Monaco
 *
 * This header file contains WFQueueManagerProxy class declaration.
 */

#ifndef _WF_QUEUE_MANAGER_PROXY_H_
#define _WF_QUEUE_MANAGER_PROXY_H_ 1

#include <boost/cstdint.hpp>
#include "address.h"
#include "workflow.h"
#include "udpinterface.h"
#include "udpclient.h"

/**
 * @brief WFQueueManagerProxy handles communication with WFQueueManager.
 *
 * In order to communicate with a Manager, a UI needs a WFQueueManagerProxy.
 * UI-Manager interaction consist in enqueue() call.<br />
 * Through enqueue() a UI is able to push into Manager's queue a Workflow.<br />
 * WFQueueManagerProxy uses an UDPClient to send enqueue() requests.
 */
class WFQueueManagerProxy
{
private:
  /**
   * @brief The UDP client that WFQueueManagerProxy will use to contact the Manager.
   */
  UDPClient _c;

public:
  /**
   * @brief Default Constructor.
   *
   * @note This should not be used.
   */
  WFQueueManagerProxy(void);

  /**
   * @brief Constructor specifying server IP address and port.
   * @param IP    Server IP address.
   * @param port  Server port.
   */
  WFQueueManagerProxy(const std::string& IP, const Port& port);

  /**
   * @brief Constructor specifying server Address.
   * @param addr  Server Address.
   */
  WFQueueManagerProxy(const Address& addr);

  /**
   * @brief Destructor.
   */
  ~WFQueueManagerProxy(void);

  /**
   * @brief Returns the current Manager Address.
   * @return  A constant reference to the UDPClient object's address .
   */
  const Address& getAddr(void) const;

  /**
   * @brief Sets current Manager Address to the provided Address.
   * @param val   The provided Address.
   */
  void setAddr(const Address& val);

  /**
   * @brief Sets current Manager Address to the provided IP and port.
   * @param IP    Server IP address.
   * @param port  Server port.
   */
  void setAddr(const std::string& IP, boost::uint16_t port);

  /**
   * @brief Ask the Manager to add provided Workflow into its queue.
   *
   * This method sends the provided Workflow to WFQueueManager module
   * via UDP, using boost asio and serialization utilities.
   *
   * @note As long as the service offered is best effort in this stage of
   * development no delivery warranties are provided.
   *
   * @param w      The provided Workflow.
   * @return       Zero if operation successful, otherwise an error code.
   */
  int enqueue(const Workflow& w);
};

#endif /* _WF_QUEUE_MANAGER_PROXY_H_ */
